package com.example.salesystem.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.salesystem.model.Product;
import com.example.salesystem.mapper.ProductMapper;
import com.example.salesystem.model.pageModel.PageQuery;
import com.example.salesystem.model.pageModel.PageResult;
import com.example.salesystem.service.IProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lishuo
 * @since 2024-05-18
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {

    /**
     * 分页查询商品列表
     * @param pageQuery
     * @return
     */
    @Override
    public PageResult<Product> getProductsByPage(PageQuery pageQuery) {
        // 1. 构造分页条件
        Page<Product> page = pageQuery.toMpPage("create_time", false);
        // 2. 分页查询
        Page<Product> res = lambdaQuery().page(page);
        // 3. 返回查询结果
        return PageResult.of(res);
    }
}
